﻿<AttributeUsage(AttributeTargets.Property, Inherited:=False, AllowMultiple:=True)> _
Public Class DateTimeValidatorAttribute
    Inherits BizBloxValidatorAttribute
    Implements iValidator

    Private m_minValueDateTime As DateTime
    Private m_maxValueDateTime As DateTime

    Public Sub New(ByVal minValueDateTime As DateTime, ByVal maxValueDateTime As DateTime)
        Me.m_minValueDateTime = minValueDateTime
        Me.m_maxValueDateTime = maxValueDateTime
    End Sub

    Public Overrides Sub Validate(ByVal o As Object) Implements iValidator.Validate
        Dim dt As DateTime = CType(o, DateTime)
        Dim input As String = dt.ToString()
        If dt < Me.m_minValueDateTime Then
            Throw New ArgumentOutOfRangeException(Me.PropertyName, input, "Date is before the minimum date.")
        ElseIf dt > Me.m_maxValueDateTime Then
            Throw New ArgumentOutOfRangeException(Me.PropertyName, input, "Date is after the maximum date.")
        End If
    End Sub

End Class
